<!-- 首页分类头部 -->
<template>
  <div class="category-list">
    <div class="category-list-header">
      <i class="iconfont icon-jiantou3" onclick="window.history.back()"></i>
      <div class="search" @click="gotoSearch">
        <i class="iconfont icon-sousuo"></i>
      </div>
      <i
        class="iconfont"
        :class="
          flag
            ? 'icon-leimupinleifenleileibie'
            : 'icon-leimupinleifenleileibie2'
        "
        @click="changeStyle"
      ></i>
    </div>
    <div class="category-list-mark">
      <div class="troule">
        <ul class="bigUl">
          <li
            :class="current == index ? selectColor : ''"
            v-for="(title, index) in titleMark"
            :key="index"
            @click="getIndex(index)"
          >
            {{ title.title }}
            <i :class="title.class"></i>
          </li>
        </ul>
        <ul>
          <li>
            <i class="iconfont icon-shaixuan" @click="showMark"></i>
            筛选
          </li>
        </ul>
      </div>
    </div>
    <div :class="listStyle">
      <div
        class="goods-list-total"
        @click="goGoods(item.cat_id)"
        v-for="(item, index) in catalist"
        :key="index"
      >
        <div class="goods-pic">
          <img :src="item.goods_thumb" alt="" />
        </div>
        <div class="grow">
          <h4>{{ item.goods_name }}</h4>
          <div class="goods-price">
            ￥<span>{{ item.shop_price }}</span
            >.00
          </div>
          <div class="goods-property">{{ item.rz_shop_name }}</div>
          <div class="goods-situation">
            <span>{{ item.buy_drp_show }}人已购买</span>
            <i class="iconfont icon-gouwuche"></i>
          </div>
        </div>
      </div>
    </div>
    <div
      class="mask"
      v-show="showMask"
      @click="hideMask"
      @touchmove.prevent
    ></div>
    <transition name="slide-fade">
      <div class="sideFeature" v-show="showMask">
        <div class="side-price">
          <h2>价格区间</h2>
          <div class="interval">
            <div class="low-price">
              <input type="text" placeholder="最低价" />
            </div>
            <span></span>
            <div class="high-price">
              <input type="text" placeholder="最高价" />
            </div>
          </div>
        </div>
        <div class="side-logo">
          <h2>品牌</h2>
          <div class="side-logos">
            <div class="select-logo">
              <span>猫人</span>
            </div>
          </div>
        </div>
        <div class="side-function">
          <div class="side-reset">重置</div>
          <div class="side-sure">确定</div>
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      current: 0,
      flag: true,
      showMask: false,
      listStyle: "bigCategoryGoodsList",
      selectColor: "selectColor",
      titleMark: [
        {
          title: "综合",
          class: "iconfont icon-sanjiao",
        },
        {
          title: "新品",
        },
        {
          title: "销量",
        },
        {
          title: "价格",
          class: "iconfont icon-sanjiao",
        },
      ],
    };
  },
  //监听属性 类似于data概念
  computed: {
    catalist(){
      return this.$store.state.goodsList
    }
  },
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    gotoSearch() {
      this.$router.push({ path: "/searchpage" });
    },
    goGoods(id) {
      this.$router.push({ name: "goodsdetail", params: { goods_id: id } });
      this.$store.dispatch("actChangeDetailData", {
        goods_id: this.$route.params.goods_id,
      });
    },
    changeStyle() {
      this.flag = !this.flag;
      if (this.flag) {
        this.listStyle = "bigCategoryGoodsList";
      } else {
        this.listStyle = "smallCategoryGoodsList";
      }
    },
    getIndex(index) {
      this.current = index;
      if (index == 0) {
        this.titleMark[0].class = "iconfont icon-xiaosanjiaoup";
      } else {
        this.titleMark[0].class = "iconfont icon-sanjiao";
      }
      if (index == 3) {
        this.titleMark[3].class = "iconfont icon-xiaosanjiaoup";
      } else {
        this.titleMark[3].class = "iconfont icon-sanjiao";
      }
    },
    showMark() {
      this.showMask = !this.showMask;
    },
    hideMask() {
      this.showMask = !this.showMask;
    },
  },
  beforeCreate() {}, //生命周期 - 创建之前
  //生命周期 - 创建完成（可以访问当前this实例）
  beforeMount() {}, //生命周期 - 挂载之前
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.$store.dispatch("goodsList", {cat_id:this.$route.params.cat_id});
  },
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang="less" scoped>
.category-list {
  .slide-fade-enter-active {
    transition: all 0.5s ease;
  }
  .slide-fade-leave-active {
    transition: all 0.5s cubic-bezier(1, 0.5, 0.8, 1);
  }
  .slide-fade-enter,
  .slide-fade-leave-to {
    transform: translateX(90%);
  }
  .selectColor {
    color: #f54;
  }
  .category-list-header {
    width: 100%;
    height: 4.4rem;
    display: flex;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;

    background-color: #fff;
    border-bottom: 1px solid #f1f1f1;
    .search {
      width: 80%;
      height: 3rem;
      position: relative;
      margin-left: 3%;
      border-radius: 1.5rem;
      border: 1px solid #ddd;
      i {
        position: absolute;
        top: 0.2rem;
        right: 0.5rem;
        height: 3rem;
        line-height: 3rem;
        color: #333;
        font-size: 2rem;
      }
    }
    i {
      font-size: 1.8rem;
      color: #999;
      width: 10%;
      text-align: center;
    }
  }
  .category-list-mark {
    .troule {
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: #fff;
      height: 4rem;
      margin-top: 5rem;
      font-size: 1.4rem;
      .bigUl {
        flex: 1;
        display: flex;
        justify-content: space-around;
        align-items: center;
      }
      ul {
        margin-right: 2rem;
      }
    }
  }
  .bigCategoryGoodsList {
    width: calc(100% - 1rem);
    margin: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-content: center;
    flex-wrap: wrap;
    .goods-list-total {
      width: 18rem;
      height: 31.25rem;
      border-radius: 1rem;
      background-color: #fff;
      margin-top: 1rem;
      .goods-pic {
        img {
          width: 17.85rem;
          height: 17.85rem;
          border-radius: 1rem;
        }
      }
      h4 {
        padding: 0.5em;
        font-weight: 400;
        font-size: 1.4rem;
        height: 3.3rem;
        line-height: 1.9rem;
        overflow: hidden;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
      }
      .goods-price {
        font-size: 1.4rem;
        font-weight: normal;
        padding: 0.5rem;
        color: #f20e28;
        span {
          font-size: 1.6rem;
          font-weight: 700;
        }
      }
      .goods-property {
        width: 16%;
        text-align: center;
        height: 1.5rem;
        line-height: 1.5rem;
        color: #fff;
        background-color: red;
        margin-left: 1rem;
      }
      .goods-situation {
        display: flex;
        justify-content: space-between;
        align-content: center;
        padding: 0.5rem;
        span {
          color: #999;
          margin-top: 1rem;
        }
        i {
          margin-top: 1rem;
          color: red;
        }
      }
    }
  }
  .smallCategoryGoodsList {
    .goods-list-total {
      width: calc(100% - 2rem);
      margin: 1rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: #fff;
      border-radius: 1rem;
      .goods-pic {
        img {
          width: 9rem;
          height: 9rem;
        }
      }
      .grow {
        flex: 1;
        margin-left: 1.5rem;
        h4 {
          padding: 0.5em;
          font-weight: 400;
          font-size: 1.4rem;
          height: 3.3rem;
          line-height: 1.9rem;
          overflow: hidden;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
        }
        .goods-price {
          font-size: 1.4rem;
          font-weight: normal;
          padding: 0.5rem;
          color: #f20e28;
          span {
            font-size: 1.6rem;
            font-weight: 700;
          }
        }
        .goods-property {
          width: 16%;
          text-align: center;
          height: 1.5rem;
          line-height: 1.5rem;
          color: #fff;
          background-color: red;
          margin-left: 1rem;
        }
        .goods-situation {
          display: flex;
          justify-content: space-between;
          align-content: center;
          padding: 0.5rem;
          span {
            color: #999;
            margin-top: 1rem;
          }
          i {
            margin-top: 1rem;
            color: red;
          }
        }
      }
    }
  }
  .mask {
    width: 100%;
    height: 100%;
    position: fixed;
    left: 0;
    top: 0;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 1;
  }
  .sideFeature {
    width: 90%;
    height: 100%;
    position: fixed;
    right: 0;
    top: 0;
    background-color: #f4f4f4;
    border-bottom-left-radius: 1rem;
    border-top-left-radius: 1rem;
    z-index: 2;
    .side-price {
      padding: 1rem;
      background-color: #fff;
      border-top-left-radius: 1rem;
      h2 {
        font-size: 1.6rem;
      }
      .interval {
        margin-top: 1rem;
        display: flex;
        justify-content: space-around;
        align-items: center;
        .low-price,
        .high-price {
          width: 50%;
          background: #f2f2f2;
          border-radius: 2rem;
          height: 4rem;
          text-align: center;
          input {
            width: 100%;
            background: transparent;
            height: 100%;
            text-align: center;
            font-size: 1.4rem;
          }
        }
        span {
          margin: 0 10px;
          height: 0.1rem;
          background: #000;
          width: 10px;
        }
      }
    }
    .side-logo {
      margin-top: 1rem;
      padding: 1rem;
      background-color: #fff;
      h2 {
        font-size: 1.6rem;
      }
      .side-logos {
        padding: 1rem;
        .select-logo {
          width: calc(33.3% - 6px);
          box-sizing: border-box;
          margin: 0 9px 10px 0;
          span {
            padding: 8px 5px;
            background: #f2f2f2;
            text-align: center;
            display: block;
            border-radius: 40px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            border: 1px solid transparent;
          }
        }
      }
    }
    .side-function {
      width: 90%;
      height: 10%;
      display: flex;
      justify-content: space-around;
      align-items: center;
      position: fixed;
      bottom: 0;
      background-color: #fff;
      border-bottom-left-radius: 1rem;
      .side-reset {
        border-radius: 20px;
        background: #fff;
        border: 1px solid #f92028;
        color: #f92028;
        text-align: center;
        padding: 1.1rem 0;
        width: 40%;
      }
      .side-sure {
        border-radius: 20px;
        background: #f92028;
        border: 1px solid #fff;
        color: #fff;
        text-align: center;
        padding: 1.1rem 0;
        width: 40%;
      }
    }
  }
}
</style>
